package java8.chapter14.test;

import java.util.function.DoubleUnaryOperator;

public class Currying {

	public static void main(String[] args) {
		DoubleUnaryOperator convertCtoF = curriedConverter(9.0 / 5, 32);
		DoubleUnaryOperator convertUSDtoGBP = curriedConverter(0.6, 0);
		DoubleUnaryOperator convertKmtoMi = curriedConverter(0.6214, 0);
		
		System.out.println(convertCtoF.applyAsDouble(24));
		System.out.println(convertUSDtoGBP.applyAsDouble(100));
		System.out.println(convertKmtoMi.applyAsDouble(20));
		
		DoubleUnaryOperator convertFtoC = expandedCurriedConverter(-32, 5.0 / 9, 0);
		System.out.println(convertFtoC.applyAsDouble(98.6));
	}

	private static DoubleUnaryOperator expandedCurriedConverter(double w, double y, double z) {
		return (double x) -> (x + w) * y + z;
	}

	private static DoubleUnaryOperator curriedConverter(double y, int z) {
		return (double x) -> x * y + z;
	}

}